package com.abc.scholarship.controller;


import com.abc.scholarship.common.utils.UserHolder;
import com.abc.scholarship.domain.dto.PlusesDTO;
import com.abc.scholarship.domain.entity.Apply;
import com.abc.scholarship.domain.page.PageDTO;
import com.abc.scholarship.domain.page.PageQuery;
import com.abc.scholarship.domain.vo.resp.ApiResult;
import com.abc.scholarship.domain.vo.resp.ApplyVO;
import com.abc.scholarship.service.ApplyService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 申请表 前端控制器
 * </p>
 *
 * @author jzw
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/apply")
@Api(tags = "申请奖学金相关接口")
public class ApplyController {
    @Resource
    private ApplyService applyService;

    /**
     * 新增数据
     *
     * @param plusesDTOList 加分项
     * @return 新增结果
     */
    @PostMapping("/save")
    @ApiOperation("学生新增申请")
    public ApiResult insert(@RequestBody List<PlusesDTO> plusesDTOList) {
        this.applyService.addApply(plusesDTOList);
        return ApiResult.success("新增成功");
    }

    @GetMapping("/teacher/list")
    @ApiOperation("老师查询申请")
    public ApiResult<PageDTO<ApplyVO>> teacherQueryApplyByPage(PageQuery query) {

        return ApiResult.success(applyService.queryApply(query));
    }
    @GetMapping("/stu/list")
    @ApiOperation("学生查询申请")
    public ApiResult<PageDTO<ApplyVO>> stuQueryApplyByPage(PageQuery query) {

        return ApiResult.success(applyService.stuQueryApply(query));
    }

    @ApiOperation("学生重新申请")
    @PutMapping("/save/{applyId}")
    public ApiResult<String> saveAgainApply(@RequestBody List<PlusesDTO> plusesDTOList,
                                            @PathVariable("applyId") Long applyId){
        applyService.updateApply(plusesDTOList, applyId);

        return ApiResult.success("更新成功");
    }

    @ApiOperation("审核申请")
    @PutMapping("/examine/{applyId}/{status}")
    public ApiResult<String> examineApply(@PathVariable("applyId") Long applyId,
                                          @PathVariable("status") Integer status){
        applyService.examineApply(applyId, status);

        return ApiResult.success("审核成功");
    }

    @ApiOperation("删除申请")
    @DeleteMapping("/delete/{id}")
    public ApiResult deleteApply(@PathVariable Long id){
        Apply apply = new Apply();
        apply.setId(id);
        applyService.removeById(apply);
        return ApiResult.success();
    }

}

